import * as step from "../../src/index"

async function run() {
    const goInstallCachedFilePath = await step.tool.install("go", "1.22.3", "tar.gz")
    step.info("go install cached file path: " + goInstallCachedFilePath)

    const shellName = "ls"
    const args = ["-l", "-a", goInstallCachedFilePath]
    step.infoCyan(`exec command: ${shellName} ${args.join(" ")}`)
    await step.exec.call(shellName, args, {
        listener: {
            stdoutLine: (line: string) => {
                step.info(line)
            },
            stderrLine: (line: string) => {
                step.error(line)
            }
        }
    })

    // Add to PATH variable, effective in current and subsequent steps
    step.info(`before addPath PATH=${process.env["PATH"]}`)
    step.addPath(`${goInstallCachedFilePath}/bin`)
    step.info(`after addPath PATH=${process.env["PATH"]}`)

    step.infoCyan(`exec command: which go`)
    await step.exec.call(`which`, ['go'], {
        listener: {
            stdoutLine: (line: string) => {
                step.info(line)
            },
            stderrLine: (line: string) => {
                step.error(line)
            }
        }
    })
}

run()